<?php
//save employee modifications
if (isset($_GET['action'])) {
    switch ($_GET['action']) {
        case "Save Changes":
            $modifyEmployeeResult = modifyEmployee($userName, $userPassHash, $_GET['accName'], $_SESSION[$_GET['accName'] . 'employee'], $_GET['empFname'], $_GET['empLname'], $_GET['startDate'], $_GET['endDate'], $_GET['empStatus'], $_GET['address'], $_GET['email'], $_GET['phoneNum'], $_GET['wage']);
            break;
        case "Delete Account":
            $deleteAccountResult = deleteAccount($_GET['accName'], $userName, $userPassHash, $_SESSION[$_GET['accName'] . 'account']);
            break;
    }
}

$getAccountsResult = getAccounts($userName, $userPassHash);

//grab the accounts
$accounts = $getAccountsResult['results'];

//parse the accounts
foreach ($accounts as &$accountsEntry) {
    $accName = $accountsEntry['accName'];

    $getAccountResult = getAccount($accName, $userName, $userPassHash);
    $_SESSION[$accName . 'account'] = $getAccountResult['results']['dataHash'];

    $account = showEmployeeInfo($_SESSION['userName'], $_SESSION['userPassHash'], $accName);
    $_SESSION[$accName . 'employee'] = $account['hash'];
    ?>
    <div class="accordion" id="employees">
        <div class="accordion-group">
            <div class="accordion-heading">
                <a class="accordion-toggle" data-toggle="collapse" data-parent="#employees"
                   href="#<?php echo($accName); ?>"> <?php echo($accName); ?>
                </a>
            </div>
            <div id="<?php echo($accName); ?>" class="accordion-body collapse">
                <div class="accordion-inner">
                    <form action="template.php" method="post">
                        <input type="hidden" name="accName" value="<?php echo($accName); ?>" />
                        <div class="control-row">
                            <div class="control-group">
                                <label class="control-label" for="empFname">First Name</label>
                                <div class="controls">
                                    <input type="text" name="empFname" id="empFname" value="<?php echo($account['empFname']); ?>" />
                                </div>
                            </div>
                            <div class="control-group">
                            </div>
                            <div class="control-group">
                            </div>
                        </div>
                        <div class="control-row">
                            <div class="control-group">
                            </div>
                            <div class="control-group">
                            </div>
                            <div class="control-group">
                            </div>
                        </div>
                        <div class="control-row">
                            <div class="control-group">
                            </div>
                            <div class="control-group">
                            </div>
                            <div class="control-group">
                            </div>
                            <td>Last Name</td>
                            <td><input type="text" name="empLname" value="<?php echo($account['empLname']); ?>" /></td>
                        </div>
                        <tr>
                            <td>Start Date</td>
                            <td><input type="text" name="startDate" value="<?php echo($account['startDate']); ?>" /></td>
                        </tr>
                        <tr>
                            <td>End Date</td>
                            <td><input type="text" name="endDate" value="<?php echo($account['endDate']); ?>" /></td>
                        </tr>
                        <tr>
                            <td>Status</td>
                            <td><input type="text" name="empStatus" value="<?php echo($account['empStatus']); ?>" /></td>
                        </tr>
                        <tr>
                            <td>Address</td>
                            <td><input type="text" name="address" value="<?php echo($account['address']); ?>" /></td>
                        </tr>
                        <tr>
                            <td>Email</td>
                            <td><input type="text" name="email" value="<?php echo($account['email']); ?>" /></td>
                        </tr>
                        <tr>
                            <td>Phone Number</td>
                            <td><input type="text" name="phoneNum" value="<?php echo($account['phoneNum']); ?>" /></td>
                        </tr>
                        <tr>
                            <td>Wage</td>
                            <td><input type="text" name="wage" value="<?php echo($account['wage']); ?>" /></td>
                        </tr>
                        <tr>
                            <td><input type="submit" name="action" value="Save Changes" /></td>
                            <td><input type="submit" name="action" value="Delete Account" /></td>
                        </tr>
                    </form>
                </div>
            </div>
        </div>
    </div>

    <?php
}
?>
